<?php
/**
 * Base process pool model
 * @author shiquanWu
 * 基础进程池服务模型
 *
 */
namespace Core;

class BaseProcessPool extends \Swoole\Process\Pool
{
    /**
     * 构造方法
     * @param int $worker_num 工作进程的数量
     * @param int $ipc_type  进程间通信的模式
     * @param int $msgqueue_key 消息队列的KEY
     */
    public function __construct($worker_num, $ipc_type = 0, $msgqueue_key = 0)
    {
        parent::__construct($worker_num, $ipc_type, $msgqueue_key);
    }

    /**
     * 启动进程池方法
     * @param  Handler $handler 处理对象
     * @return bool
     */
    public function run($handler)
    {
        $this->on('WorkerStart', array($handler, 'onWorkerStart'));     //worker进程启动
        $this->on('WorkerStop', array($handler, 'onWorkerStop'));       //worker进程结束
        $this->start();
    }
}
